
$(function(){
	$.ajax({
		type : "POST",
		url :"../PostSendController/findByCondition.action",
		data : null,
		success : function(data) {
			var str="";
			var obj=eval("("+data+")");
			$.each(obj, function(i, data) {
				  str='<div class="panel panel-default">'+'<div class="panel-heading">'+data.title+
				  '<span style="float:right">'+data.uname+"&nbsp;&nbsp;"+data.receiveTime+'</span>'+
					'</div>'+'<div class="panel-body">'+'<a href="../PostReplyController/findByConditionfront.action?topostId='+data.postId+'">'
							 //'<a href="../MenuController/postDetailFront.action?postId='+data.postId+'">'
					+data.content+'</a></div></div>';
				   $("#postContent").append(str);
			});
		},
		error : function(request) {
			toastr.error("发送失败");
		}
	});
	
});
$("#sendnewEmail").click(function() {
	$("#emailEdit").bootstrapTable('refresh');
	$('#newEmail').modal('show');
	resetEmail();

});


$("#sendPost").click(function() {
	var form = "#PostSendForm";
	var url = "../PostSendController/add.action";
	var type = "PostSend";
	submitEmailadd(form, url, type);
});



function submitEmailadd(form, url, type) {
	$.ajax({
		type : "POST",
		url : url,
		data : /* $(form).serialize(), */
		{
			"postTitle" : $("#postTitle").val(),
			"postContent" : $("#postContent01").val(),
		},
		success : function(data) {
		    alert($("#postContent01").val());
			window.location.href = "../MenuController/postListfront.action";
		
		},
		error : function(request) {
			toastr.error("发送失败");
		}
	});
}


$('#reset').click(function() {
	$('#postTitle').val(""), $('#postContent').val("")

});

function resetEmail() {
	$('#postTitle').val(""), $('#postContent').val("")
}
/**
 * 删除收件箱
 */

$('#deleteMailFromuser').click(function() {
   
	var type = 'PostReply';
	var ids = getEmailSelection(type, 'id');

	if (ids.length > 0) {
		$.ajax({
			url : "../PostReplyController/delete.action",
			data : {
				ids : ids.join(','),
				state : 0,
			// userId: 2
			},
			dataType : 'json',
			success : function(d) {
			
				$('#' + type).bootstrapTable('refresh');
				if (d.success != "0" && typeof (d.success) != "undefined") {
					toastr.success("成功删除" + d.success + "条!");
				}
				if (typeof (d.success) == "undefined") {
					toastr.success("成功删除" + ids.length + "条!");
				}
			}
		});
	} else {
		toastr.warning("请勾选删除的记录!");
	}
});

/**
 * 删除收件箱
 */

$('#deleteMailTouser').click(function() {

	var type = 'PostSend';
	var ids = getEmailSelection(type, 'id');
	if (ids.length > 0) {
		$.ajax({
			url : "../PostSendController/delete.action",
			data : {
				ids : ids.join(','),
				state : 0,
			// userId: 2
			},
			dataType : 'json',
			success : function(d) {
				$('#' + type).bootstrapTable('refresh');
				if (d.success != "0" && typeof (d.success) != "undefined") {
					toastr.success("成功删除" + d.success + "条!");
				}
				if (typeof (d.success) == "undefined") {
					toastr.success("成功删除" + ids.length + "条!");
				}
			}
		});
	} else {
		toastr.warning("请勾选删除的记录!");
	}
});

function getEmailSelection(type, parm) {
	return $.map($('#' + type).bootstrapTable('getSelections'), function(row) {
		return eval('row.' + parm);
	});
}
